<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo  Q::ini('appini/app_title')." ". Q::ini('appini/version');?></title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/icon.css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="js/jquery-easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>

<script language="javascript">
function newsupplier(){  
    $('#dlg').dialog('open').dialog('setTitle','添加供应商');  
    $('#fm').form('clear');  
    url = '<?=url("supplier/new")?>';  
} 

function editsupplier(){
	var row = $('#dg').datagrid('getSelected');  
    if (row){  
        $('#dlg').dialog('open').dialog('setTitle','编辑供应商');  
        $('#fm').form('load',row);  
        //url = 'update.php?id='+row.id;  
		url = '<?=url("supplier/update")?>';
    } 
	else{
		$.messager.show({
			'title': "提示",
			'msg': "请选择要编辑的记录."	
		});	
	} 		
}

function savesupplier(){  
	$('#fm').form('submit',{  
		url: url,  
		onSubmit: function(){  
			return $(this).form('validate');  
		},  
		success: function(result){  
			var result = eval('('+result+')');  
			if (result.errorMsg){  
				$.messager.show({  
					title: '出错了',  
					msg: result.errorMsg  
				});  
			} else {  
				$('#dlg').dialog('close');      // close the dialog  
				$('#dg').datagrid('reload');    // reload the user data  
			}  
		}  
	});  
}  

function destroysupplier(){  
    var row = $('#dg').datagrid('getSelected');  
    if (row){  
        $.messager.confirm('确认','您确认要删除该记录吗?',function(r){  
            if (r){  
                $.post('<?=url("supplier/destroy")?>',{id:row.supplier_id},function(result){  
                    if (result.success){  
                        $('#dg').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.show({   // show error message  
                            title: '出错了',  
                            msg: result.errorMsg  
                        });  
                    }  
                },'json');  
            }  
        });  
    }
	else{
		$.messager.show({   // show error message  
			title: '提示',  
			msg: "请选择要删除的记录."
		});  	
	}  
}
</script>
</head>

<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    
    <div region="center" style="width: 500px; height: 300px; padding: 1px;overflow-y: hidden">
        <table id="dg" title="商品供应商"  class="easyui-datagrid" url="<?=url("supplier/list")?>"  toolbar="#toolbar"  rownumbers="true" fitColumns="true" singleSelect="true" iconCls="icon-save"  pagination="true" fit="true">  
        	<thead>  
                <tr>  
                    <th field="code" width="30">供应商编码</th>  
                    <th field="name" width="50">供应商名称</th>  
                    <th field="linker" width="40">联系人</th>
                    <th field="telephone" width="50">固定电话</th>
                    <th field="mobile" width="50">移动电话</th>
                    <th field="qq" width="50">QQ</th>
                    <th field="email" width="50">电子邮箱</th>
                    <th field="address" width="50">地址</th>
                </tr>  
        	</thead>  
    	</table>  
    	<div id="toolbar">  
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newsupplier()">新增</a>  
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editsupplier()">编辑</a>  
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroysupplier()">删除</a>  
    	</div>  
    </div>
	<div id="dlg" class="easyui-dialog" style="width:400px;height:450px;padding:10px 20px" closed="true" buttons="#dlg-buttons"  modal="true">  
        <div class="ftitle">详细信息</div>  
        <form id="fm" method="post">  
            <div class="fitem">  
                <label>供应商编码:</label>  
                <input name="code" id="code" >  
            </div>  
            <div class="fitem">  
                <label>供应商名称:</label>  
                <input name="name" id="name" class="easyui-validatebox" required="true">  
            </div>  
            <div class="fitem">  
                <label>联系人:</label>  
                <input name="linker" id="linker">  
            </div>
            <div class="fitem">  
                <label>固定电话:</label>  
                <input name="telephone" id="telephone">  
            </div>
            <div class="fitem">  
                <label>移动电话:</label>  
                <input name="mobile" id="mobile" >  
            </div>
            <div class="fitem">  
                <label>Q&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q:</label>  
                <input name="qq" id="qq" >  
            </div>
            <div class="fitem">  
                <label>电子邮箱:</label>  
                <input name="email" id="email" >  
            </div>
            <div class="fitem">  
                <label>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址:</label>  
                <input name="address" id="address" >  
            </div>
            <div class="fitem">  
                <label>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</label>
                <textarea name="remark" id="remark"></textarea>  
            </div>
            <input name="supplier_id" id="supplier_id" type="hidden"  />
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="savesupplier()">保存</a>  
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
    </div>       
</body>
</html>